﻿/*
**主营业务申请页面
*/
Chenxin.UI.MainBusinessApplyPage = Chenxin.extend(Chenxin.UI.AddPageCommon, {
    actionUrl: "/service/logic/MainBusinessApply.ashx",
    createForm: function() {
        return new Chenxin.UI.MainBusinessApplyForm({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl + '?op=getmarkedls',
            domId: 'page',
            pageSize: 10,
            renderTo: 'divMarkedLs',
            data: {},
            autoLoad:false,
            render: function(data) {
                document.getElementById('divMarkedLs').innerHTML = data;
            }
        });
    },
    customerInit: function() {
    },
    initEvent: function() {
        var objPg = this;
        /*************事件：提交*************/
        $("#aSubmit").click(function() {
            if (objPg.form.ApplyInfo != undefined) {
                objPg.form.op = "upd";
            }
            objPg.form.save();
        });
        /*************事件：关闭*************/
        $("#aClose").click(function() {
            window.close();
        });
        /*************事件：查看备案*************/
        $("#aViewRecord").click(function() {
            var HouseId;
            if (objPg.form.ApplyInfo != undefined) {
                HouseId = objPg.form.ApplyInfo.HouseId;
            } else if (objPg.form.HouseInfo != undefined) {
                HouseId = objPg.form.HouseInfo.HouseId;
            }
            if (objPg.MarkedListForm == undefined) {
                objPg.MarkedListForm = new Chenxin.UI.MarkedListForm();
                objPg.grid.reload({ houseid: HouseId });
                objPg.MarkedListForm.show();
            } else {
                objPg.grid.reload({ houseid: HouseId });
                objPg.MarkedListForm.show();
            }
        });
    }
});

/*
**备案窗体
*/
Chenxin.UI.MarkedListForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/viewHouse.ashx',
    id: 'jqmMarkedList',
    renderTo: 'divMarkedList',
    title:'查看备案',
    autoHide: true,
    jqmWidth: 700,
    autoCheckPermit:false,
    createForm: function() {
        return "<table class='tbl_f jqTabWh'><tbody><tr><td><div id='divMarkedLs'></div></td></tr><tr><td><div class='btn btn2 fr' style='width:55px'><a href='javascript:void(0)' title='关闭' id='aCloseForm'><span>关闭</span></a></div></td></tr></tbody></table>";
    },
    initEvent: function() {
        var objFrm = this;
        $("#aCloseForm").live("click",function(){
            objFrm.hide();
        });
    }
});

/*
**主营业务申请窗体
*/
Chenxin.UI.MainBusinessApplyForm = Chenxin.extend(Chenxin.UI.AddFormCommon, {
    actionUrl: "/service/logic/MainBusinessApply.ashx",
    id: "divMainBusiness",
    createComboList: function() {
        //获取初始Combo的值
        var jsonInitVal = this.initComboVal();
        var objForm = this;
        //房屋性质
        var comboHouseProperty = new Chenxin.UI.Combo({
            containerId: '#HouseProperty',
            name: 'HouseProperty',
            tbxWidth: 120,
            colWidth: 80,
            required: true,
            initValue: jsonInitVal.HouseProperty + "",
            items: comboCommon.HouseProperty,
            onSelected: function() {
                var strType = $("input[name=BusinessType]:checked").val();
                var strProperty = "";
                if (this._val != this.defVal) {
                    strProperty = this._val;
                }
                var strBargainPrice = $("#txtBargainPrice").val();
                objForm.setStandardCommission(strType, strProperty, strBargainPrice);
            }
        });

        //区域
        var comboRegion = new Chenxin.UI.ParameterCombo({
            name: 'Region',
            containerId: '#Region',
            key: 'System.Region',
            tbxWidth: 120,
            inModelType: 'txt',
            param: { filter: 'bycity' },
            initValue: jsonInitVal.Region,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBlock.clearItems();
                } else {
                    comboBlock.param.subkey = this.getValue();
                    comboBlock.param.recordid = this.getValueRecord()['id'];
                    comboBlock.reload();
                }
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != this.defVal) {
                    comboBlock.param.subkey = this.getValue();
                    comboBlock.param.recordid = this.getValueRecord()['id'];
                    comboBlock.reload(jsonInitVal.Block);
                }
            }
        });
        //板块
        var comboBlock = new Chenxin.UI.ParameterCombo({
            containerId: '#Block',
            key: 'System.Block',
            tbxWidth: 120,
            colWidth: 90,
            inModelType: 'txt',
            autoLoad: false,
            required: true
        });
        //合同归属（城市）
        var comboBargainCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#BargainCityId',
            name: 'BargainCityId',
            tbxWidth: 120,
            inModelType: 'all',
            txtModelName: 'BargainCityName',
            initValue: jsonInitVal.BargainCityId,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBargainCompanyId.clearItems();
                } else {
                    comboBargainCompanyId.param.fatherid = this.getValue();
                    comboBargainCompanyId.reload();
                }
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != this.defVal) {
                    comboBargainCompanyId.param.fatherid = newVal;
                    comboBargainCompanyId.reload(jsonInitVal.BargainCompanyId);
                }
            }
        });
        //合同归属（公司）
        var comboBargainCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#BargainCompanyId',
            name: 'BargainCompanyId',
            inModelType: 'all',
            txtModelName: 'BargainCompanyName',
            tbxWidth: 120,
            autoLoad: false,
            required: true
        });
        //下家门店
        var comboBuyerDepartId = new Chenxin.UI.DepartTreeCombo({
            containerId: '#txtBuyerDepartId',
            textBoxId: 'txtBuyerDepartId',
            name: 'BuyerDepartId',
            inModelType: 'all',
            txtModelName: 'BuyerDepartName',
            required: true,
            onSelected: function() {
                if (this.getValue() != this.defVal) {
                    comboBuyerUserId.loadUser(this.getValue());
                }
            }
        });
        //下家业务员
        var comboBuyerUserId = new Chenxin.UI.RichModelTreeCombo({
            containerId: '#txtBuyerUserId',
            textBoxId: 'txtBuyerUserId',
            inModelType: 'all',
            txtModelName: 'BuyerUserName',
            required: true,
            singleSelect: true,
            initValue: jsonInitVal.BuyerUserId,
            name: 'BuyerUserId'
        });
        //房屋用途
        var comboHouseUse = new Chenxin.UI.ParameterCombo({
            containerId: '#HouseUse',
            name: 'HouseUse',
            key: 'House.Use',
            inModelType: 'txt',
            tbxWidth: 120,
            initValue: jsonInitVal.HouseUse,
            required: true
        });
        //建筑类型
        var comboBuildingType = new Chenxin.UI.ParameterCombo({
            containerId: '#BuildingType',
            name: 'BuildingType',
            key: 'Building.Type',
            inModelType: 'txt',
            autoLoad: true,
            initValue: jsonInitVal.BuildingType,
            tbxWidth: 120,
            required: true
        });
        this.setComboList = [comboBuyerDepartId, comboBuyerUserId];
        return [comboHouseProperty, comboRegion, comboBlock, comboBargainCityId, comboBargainCompanyId, comboBuyerDepartId, comboBuyerUserId, comboHouseUse, comboBuildingType];
    },
    setStandardCommission: function(strType, strProperty, strBargainPrice) {

        if (strType != "" && strProperty != "" && strBargainPrice != "") {
            Chenxin.ajax({
                type: "post",
                async: false,
                dataType: "json",
                url: this.actionUrl,
                data: { op: 'getstandcomm', BusinessType: strType, HouseProperty: strProperty, BargainPrice: strBargainPrice },
                onSuccess: function(data) {
                    $("#txtVStandardCommision").val(data.VCommission);
                    $("#txtBStandardCommision").val(data.BCommission);
                }
            });
        } else {
            $("#txtVStandardCommision").val("");
            $("#txtBStandardCommision").val("");
        }
    },
    initFormValidator: function() {
        //房源地址
        $("#txtNewHouseAddress").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房源地址！",
            onfocus: "房源地址为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "房源地址不能为空！"
            },
            onerror: "房源地址不能为空！"
        });
        //面积
        $("#txtArea").formValidator({
            validatorgroup: this.id,
            onshow: "请输入面积！",
            onfocus: "面积为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "面积不能为空！"
            },
            onerror: "面积不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "面积不能为非数值类型！"
        });
        //合同标的
        $("#txtBargainPrice").formValidator({
            validatorgroup: this.id,
            onshow: "请输入合同标的！",
            onfocus: "合同标的为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "合同标的不能为空！"
            },
            onerror: "合同标的不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非数值格式！"
        });
        //产权证号
        $("#txtPropertyCode").formValidator({
            validatorgroup: this.id,
            onshow: "请输入产权证号！",
            onfocus: "产权证号为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "产权证号不能为空！"
            },
            onerror: "产权证号不能为空！"
        });
        //上家姓名
        $("#txtVenderName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家姓名！",
            onfocus: "上家姓名为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "上家姓名不能为空！"
            },
            onerror: "上家姓名不能为空！"
        });
        //上家身份证
        $("#txtVenderNo").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家身份证号！",
            onfocus: "上家身份证号为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "上家身份证号不能为空！"
            },
            onerror: "上家身份证号不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isIdCardNo();
            },
            onerror: "身份证格式不正确！"
        });
        //上家手机
        $("#txtVenderMobile").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家手机！",
            onfocus: "上家手机为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "上家手机不能为空！"
            },
            onerror: "上家手机不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isMobile();
            },
            onerror: "手机格式不正确！"
        });
        //下家姓名
        $("#txtBuyerName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家姓名！",
            onfocus: "下家姓名为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "下家姓名不能为空！"
            },
            onerror: "下家姓名不能为空！"
        });
        //下家身份证
        $("#txtBuyerNo").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家身份证号！",
            onfocus: "下家身份证号为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "下家身份证号不能为空！"
            },
            onerror: "下家身份证号不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isIdCardNo();
            },
            onerror: "身份证格式不正确！"
        });
        //下家手机
        $("#txtBuyerMobile").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家手机！",
            onfocus: "下家手机为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "下家手机不能为空！"
            },
            onerror: "下家手机不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isMobile();
            },
            onerror: "手机格式不正确！"
        });
        //上家确认佣收
        $("#txtVRealCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家确认佣收！",
            onfocus: "上家确认佣收为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //上家事前折佣
        $("#txtVCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家事前折佣！",
            onfocus: "上家事前折佣为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //上家咨询费
        $("#txtVConsulting").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家咨询费！",
            onfocus: "上家咨询费为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家确认佣收
        $("#txtBRealCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家确认佣收！",
            onfocus: "下家确认佣收为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家事前折佣
        $("#txtBCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家事前折佣！",
            onfocus: "下家事前折佣为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家咨询费
        $("#txtBConsulting").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家咨询费！",
            onfocus: "下家咨询费为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
    },
    manualPreCheck: function() {

        var bRet = true;
        var RowCnt = 0;
        var isValidOfOther = true;
        //业绩申请-点数分配情况
        $("#tbPointInfo tr").each(function() {

            //数据领域
            if ($(this).find("input[name='DepartId']").length > 0) {
                //门店
                var objDepart = $(this).find("input[name=DepartId]:eq(0)");
                if (objDepart.val() == "") {
                    alert("请输入门店");
                    objDepart.focus();
                    bRet = false;
                    isValidOfOther = false;
                    return false;
                }
                //业务员
                var objUser = $(this).find("input[name=EmployeeId]:eq(0)");
                if (objUser.val() == "") {
                    alert("请输入业务员");
                    objUser.focus();
                    bRet = false;
                    isValidOfOther = false;
                    return false;
                }
                //点数
                var objPoint = $(this).find("input[name=Point]:eq(0)");
                if (objPoint.val() == "") {
                    alert("请输入点数");
                    objPoint.focus();
                    isValidOfOther = false;
                    bRet = false;
                    return false;
                }
                //数值
                if (objPoint.val().isNum() == false) {
                    alert("请输入数值");
                    objPoint.focus();
                    isValidOfOther = false;
                    bRet = false;
                    return false;
                } else {
                    RowCnt = RowCnt + parseFloat(objPoint.val());
                }
            }
        });
        //无点数分配信息
        if (RowCnt != 10 && isValidOfOther) {
            alert("点数分配不正确");
            bRet = false;
        }
        return bRet;
    },
    initEvent: function() {
        var objFrm = this;
        /*******************事件：合同类型选择******************/
        $("input[name = BusinessType]").click(function() {
            var strType = $("input[name=BusinessType]:checked").val();
            var strProperty = "";
            if (objFrm.comboList[0].getValue() != objFrm.comboList[0].defVal) {
                strProperty = objFrm.comboList[0].getValue();
            }
            var strBargainPrice = $("#txtBargainPrice").val();
            objFrm.setStandardCommission(strType, strProperty, strBargainPrice);
        });
        /*******************事件：合同标的失去焦点******************/
        $("#txtBargainPrice").blur(function() {
            var strType = $("input[name=BusinessType]:checked").val();
            var strProperty = "";
            if (objFrm.comboList[0].getValue() != objFrm.comboList[0].defVal) {
                strProperty = objFrm.comboList[0].getValue();
            }
            var strBargainPrice = $("#txtBargainPrice").val();
            objFrm.setStandardCommission(strType, strProperty, strBargainPrice);
        });

        /*******************事件：添加点数分配******************/
        $("#aAddPointInfo").click(function() {
            objFrm.createTr(true);
        });
        /*****************事件：删除点数分配信息****************/
        $("A[name='aDelPointInfo']").live("click", function() {
            //行位置
            var trIndex = $(this).parents("tbody:first").children("tr").index($(this).parents("tr:first"));

            if ($(this).parents("tbody:first").children("tr").length == 3) {
                alert("点数分配为必要信息,不可全删除");
            } else {
                if (confirm("确定要删除吗？")) {
                    var objOwerTr = $(this).parents("tr:first");
                    $(objOwerTr).remove();
                    objFrm.lsObjPoint.splice(trIndex, 1);
                    objFrm.lsComboPointInfo.splice(trIndex, 1);
                }
            }
        });
    },
    createTrComboList: function(idxRow, PointInfo) {
        //客户类型
        var strCreate = "";
        strCreate = strCreate + "var comboBuyerOrVenderInfo_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.Combo({";
        strCreate = strCreate + "   containerId: '#BuyerOrVenderInfo_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "   name: 'BuyerOrVenderInfo',";
        strCreate = strCreate + "   addPleaseSelected:false,";
        strCreate = strCreate + "   tbxWidth: 40,";
        if (PointInfo != undefined) {
            strCreate = strCreate + "   initValue:'" + PointInfo.BuyerOrVenderInfo + "',";
        }
        strCreate = strCreate + "   items:comboCommon.DealPerson";
        strCreate = strCreate + "});";

        //业务员
        strCreate = strCreate + "var comboEmployeeId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.RichModelTreeCombo({";
        strCreate = strCreate + "    textBoxId:'txtEmployeeId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "    inModelType:'all',";
        strCreate = strCreate + "	 txtModelName:'Employee',";
        strCreate = strCreate + "    singleSelect:true,";
        strCreate = strCreate + "    required:true,";
        strCreate = strCreate + "    name:'EmployeeId'";
        strCreate = strCreate + "});";

        //店长
        strCreate = strCreate + "var comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.RichModelTreeCombo({";
        strCreate = strCreate + "    textBoxId:'txtDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "    inModelType:'all',";
        strCreate = strCreate + "	 txtModelName:'DeparterManagerName',";
        strCreate = strCreate + "    singleSelect:true,";
        strCreate = strCreate + "    required:true,";
        strCreate = strCreate + "    name:'DeparterManagerId'";
        strCreate = strCreate + "});";

        //高经
        strCreate = strCreate + "var comboMangerId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.RichModelTreeCombo({";
        strCreate = strCreate + "    textBoxId:'txtMangerId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "    inModelType:'all',";
        strCreate = strCreate + "	 txtModelName:'MangerName',";
        strCreate = strCreate + "    singleSelect:true,";
        strCreate = strCreate + "    name:'MangerId'";
        strCreate = strCreate + "});";

        //区经
        strCreate = strCreate + "var comboRegionMangerId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.RichModelTreeCombo({";
        strCreate = strCreate + "    textBoxId:'txtRegionMangerId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "    inModelType:'all',";
        strCreate = strCreate + "	 txtModelName:'RegionManagerName',";
        strCreate = strCreate + "    singleSelect:true,";
        strCreate = strCreate + "    name:'RegionManagerId'";
        strCreate = strCreate + "});";

        //总监
        strCreate = strCreate + "var comboMajordomoId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.RichModelTreeCombo({";
        strCreate = strCreate + "    textBoxId:'txtMajordomoId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "    inModelType:'all',";
        strCreate = strCreate + "	 txtModelName:'MajordomoName',";
        strCreate = strCreate + "    singleSelect:true,";
        strCreate = strCreate + "    name:'MajordomoId'";
        strCreate = strCreate + "});";

        //门店
        strCreate = strCreate + "var comboDepartId_" + idxRow.toString().padLeft(2, "0") + " = new Chenxin.UI.DepartTreeCombo({";
        strCreate = strCreate + "   textBoxId: 'txtDepartId_" + idxRow.toString().padLeft(2, "0") + "',";
        strCreate = strCreate + "   name: 'DepartId',";
        strCreate = strCreate + "   inModelType:'all',";
        strCreate = strCreate + "   txtModelName:'Depart',";
        strCreate = strCreate + "   onSelected:function(node,el){";

        strCreate = strCreate + "       if (!node.select) {";
        strCreate = strCreate + "   		comboEmployeeId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboMangerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboRegionMangerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboMajordomoId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		return false;";
        strCreate = strCreate + "       }";

        strCreate = strCreate + "   	if( this.getValue() != this.defVal ){";
        strCreate = strCreate + "   		comboEmployeeId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboMangerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";

        strCreate = strCreate + "   		comboRegionMangerId_" + idxRow.toString().padLeft(2, "0") + ".reset();";
        strCreate = strCreate + "   		comboMajordomoId_" + idxRow.toString().padLeft(2, "0") + ".reset();";

        //strCreate = strCreate + "debugger;" + "\n";
        strCreate = strCreate + "           Chenxin.ajax({";
        strCreate = strCreate + "               url: '" + this.actionUrl + "',";
        strCreate = strCreate + "               data: {DepartId:this.getValue(),op:'getparents'},";
        strCreate = strCreate + "               type: 'get',";
        strCreate = strCreate + "               dataType: 'json',";
        strCreate = strCreate + "               async: false,";
        strCreate = strCreate + "               onSuccess: function(data, msg) {";

        //店长
        strCreate = strCreate + "                   if (data.DeparterManagerId != undefined){";
        strCreate = strCreate + "                       comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + ".setValue(data.DeparterManagerId)";
        strCreate = strCreate + "                   }";
        //高经
        strCreate = strCreate + "                   if (data.MangerId != undefined){";
        strCreate = strCreate + "                       comboMangerId_" + idxRow.toString().padLeft(2, "0") + ".setValue(data.MangerId)";
        strCreate = strCreate + "                   }";
        //区经
        strCreate = strCreate + "                   if (data.RegionMangerId != undefined){";
        strCreate = strCreate + "                       comboRegionMangerId_" + idxRow.toString().padLeft(2, "0") + ".setValue(data.RegionMangerId)";
        strCreate = strCreate + "                   }";
        //总监
        strCreate = strCreate + "                   if (data.MajordomoId != undefined){";
        strCreate = strCreate + "                       comboMajordomoId_" + idxRow.toString().padLeft(2, "0") + ".setValue(data.MajordomoId)";
        strCreate = strCreate + "                   }";

        strCreate = strCreate + "               }";
        strCreate = strCreate + "           });";

        strCreate = strCreate + "   		comboEmployeeId_" + idxRow.toString().padLeft(2, "0") + ".loadUser(this.getValue());";
        strCreate = strCreate + "   		comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0") + ".loadUser(this.getValue());";
        strCreate = strCreate + "   		comboMangerId_" + idxRow.toString().padLeft(2, "0") + ".loadUser(this.getValue());";
        strCreate = strCreate + "   	}";
        strCreate = strCreate + "   }";
        strCreate = strCreate + "});";

        eval(strCreate);

        if (this.lsComboPointInfo == undefined) {
            this.lsComboPointInfo = [];
        }
        var trCombo = [];
        trCombo.push(eval("comboBuyerOrVenderInfo_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboEmployeeId_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboDeparterManagerId_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboMangerId_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboRegionMangerId_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboMajordomoId_" + idxRow.toString().padLeft(2, "0")));
        trCombo.push(eval("comboDepartId_" + idxRow.toString().padLeft(2, "0")));

        //初始设定
        if (PointInfo != undefined) {
            for (var idxCnt = 1; idxCnt < trCombo.length; idxCnt++) {
                if (PointInfo[trCombo[idxCnt].name] != "00000000-0000-0000-0000-000000000000") {
                    trCombo[idxCnt].setValue(PointInfo[trCombo[idxCnt].name]);
                }
            }
            //业务员
            trCombo[1].loadUser(PointInfo[trCombo[6].name]);
            //店长
            trCombo[2].loadUser(PointInfo[trCombo[6].name]);
            //高经
            trCombo[3].loadUser(PointInfo[trCombo[6].name]);
        }

        this.lsComboPointInfo.push(trCombo);
    },
    createTr: function(bFocus, PointInfo) {
        //当前点数分配行数
        if (this.MaxPointInfo == undefined) {
            this.MaxPointInfo = 0;
        }
        var curRowCnt = this.MaxPointInfo;
        //最后一个行
        objLastTr = $("#tbPointInfo").find("tr:last").prev();

        //点数
        var Point = "";
        if (PointInfo != undefined) {
            Point = PointInfo.Point;
        }

        //点数分配行信息
        var htmlTr = "";
        htmlTr = htmlTr + "<tr id='trPointInfo_" + curRowCnt.toString().padLeft(2, "0") + "'>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <div id='BuyerOrVenderInfo_" + curRowCnt.toString().padLeft(2, "0") + "' style='z-index:" + (100 - curRowCnt).toString() + "; margin-right: 2px;' class='SelectWrapSingle'></div>";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtDepartId_" + curRowCnt.toString().padLeft(2, "0") + "' name='DepartId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtEmployeeId_" + curRowCnt.toString().padLeft(2, "0") + "' name='EmployeeId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtDeparterManagerId_" + curRowCnt.toString().padLeft(2, "0") + "' name='DeparterManagerId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtMangerId_" + curRowCnt.toString().padLeft(2, "0") + "' name='MangerId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtRegionMangerId_" + curRowCnt.toString().padLeft(2, "0") + "' name='RegionManagerId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtMajordomoId_" + curRowCnt.toString().padLeft(2, "0") + "' name='MajordomoId' class='inputbox_n fl' style='width:60px' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <input type=text id='txtPoint_" + curRowCnt.toString().padLeft(2, "0") + "' name='Point' class='inputbox_n fl' style='width:60px' value='" + Point + "' />";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "    <td>";
        htmlTr = htmlTr + "        <a href='javascript:void(0)' name='aDelPointInfo'>删除</a>";
        htmlTr = htmlTr + "    </td>";
        htmlTr = htmlTr + "</tr>";
        //添加行数据
        $(objLastTr).before(htmlTr);

        if (PointInfo == undefined) {
            //生成下拉框
            this.createTrComboList(curRowCnt);
            //聚焦
            if (bFocus == true) {
                $(objLastTr).prev().find("input:eq(0)").focus();
            }
        } else {
            //生成下拉框
            this.createTrComboList(curRowCnt, PointInfo);
        }

        if (this.lsObjPoint == undefined) {
            this.lsObjPoint = [];
        }
        this.lsObjPoint.push("#txtPoint_" + curRowCnt.toString().padLeft(2, "0"));
        this.MaxPointInfo = this.MaxPointInfo + 1;
    },
    saveSucc: function() {
        //提交成功后转到查询页面
        window.location.href = "/page/Contract_ApplyInfo/ShowListContractApply.aspx";
    },
    afterGetFormJson: function(json) {
        //房源地址
        json.HouseAddress = json.NewHouseAddress;
        if (this.form.HouseInfo != undefined) {

            var HouseType;
            json.VenderCityId = this.form.HouseInfo.CityId;
            json.VenderCompanyId = this.form.HouseInfo.CompanyId;
            json.VenderCompanyName = this.form.HouseInfo.CompanyName;
            json.VenderDepartId = this.form.HouseInfo.OprDepartId;
            json.VenderUserId = this.form.HouseInfo.OprPersonId;

            json.CommunityId = this.form.HouseInfo.CommunityId;
            json.CommunityAddress = this.form.HouseInfo.CommunityAddress;
            json.Community = this.form.HouseInfo.Community;
            //            json.CurrentFloor = this.form.HouseInfo.Cur_Floor;
            //            json.TotalFloor = this.form.HouseInfo.Total_Floor;
            //            json.BuildingType = this.form.HouseInfo.BuildingType;
            //            json.HouseUse = this.form.HouseInfo.HouseUse;
            json.CompleteYear = this.form.HouseInfo.CompleteYear;
            json.Fitment = this.form.HouseInfo.Fitment;

            if (this.form.HouseInfo.Model_Room == null) {
                HouseType = "-/";
            } else {
                HouseType = this.form.HouseInfo.Model_Room + "/";
            }
            if (this.form.HouseInfo.Model_Hall == null) {
                HouseType = HouseType + "-/";
            } else {
                HouseType = HouseType + this.form.HouseInfo.Model_Hall + "/";
            }
            if (this.form.HouseInfo.Model_Toilet == null) {
                HouseType = HouseType + "-";
            } else {
                HouseType = HouseType + this.form.HouseInfo.Model_Toilet;
            }
            json.HouseType = HouseType;

        }

        json.PointRemark = $("#txtaPointRemark").val();

        //下家门店
        if (this.form.comboList[4].currentNode != undefined) {
            json.BuyerCityId = this.form.comboList[4].currentNode.cityid;
            json.BuyerCityName = this.form.comboList[4].currentNode.cityname;
            json.BuyerCompanyId = this.form.comboList[4].currentNode.companyid;
            json.BuyerCompanyName = this.form.comboList[4].currentNode.companyname;
        }

        var JsonList = [];
        var trJson = {};
        this.form.additionalParam = {};

        //点数分配情况
        var ModelType;
        for (var idxCntOfPoint = 0; idxCntOfPoint < this.form.lsObjPoint.length; idxCntOfPoint++) {
            trJson = {};
            for (var idxCntOfCombo = 0; idxCntOfCombo < this.form.lsComboPointInfo[idxCntOfPoint].length; idxCntOfCombo++) {
                ModelType = this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].inModelType;
                if (ModelType == "txt") {
                    if (this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != undefined &&
                        this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != "") {
                        trJson[this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].name] =
                               this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getText();
                    }
                } else if (ModelType == "val") {
                    if (this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != undefined &&
                    this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != "") {
                        trJson[this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].name] =
                               this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue();
                    }
                }
                else {
                    if (this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != undefined &&
                        this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue() != "") {
                        trJson[this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].name] =
                                this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getValue();
                        trJson[this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].txtModelName] =
			                    this.form.lsComboPointInfo[idxCntOfPoint][idxCntOfCombo].getText();
                    }
                }
            }
            trJson["Point"] = $(this.form.lsObjPoint[idxCntOfPoint]).val();
            JsonList.push(trJson);
        }
        //客户端点数分配信息
        if (JsonList.toString() != "") {
            this.form.additionalParam.PointInfo = "[" + JsonList.toString() + "]";
        }
    },
    initForm: function() {
        //初始房源信息
        if ($("#ctl00_main_hidHouseInfo").val() != "") {
            var houseInfo = eval("(" + $("#ctl00_main_hidHouseInfo").val() + ")");
            //有房源信息
            this.HouseInfo = houseInfo;
        }
        //初始业绩申请信息
        if ($("#ctl00_main_hidApplyInfo").val() != "") {
            var applyInfo = eval("(" + $("#ctl00_main_hidApplyInfo").val() + ")");
            //有房源信息
            this.ApplyInfo = applyInfo;
        }
        //点数分配信息
        if ($("#ctl00_main_hidPointInfo").val() != "") {
            var pointInfo = eval("(" + $("#ctl00_main_hidPointInfo").val() + ")");
            //点数分配信息
            this.PointInfo = pointInfo;
        }
        //初始化人员信息
        if ($("#ctl00_main_hidUserInfo").val() != "") {
            var userInfo = eval("(" + $("#ctl00_main_hidUserInfo").val() + ")");
            //点数分配信息
            this.UserInfo = userInfo;
        }
    },
    initComboVal: function() {
        var jsonInitVal = {};
        if (this.HouseInfo != undefined) {
            jsonInitVal.Block = this.HouseInfo.Block;
            jsonInitVal.Region = this.HouseInfo.Region;
            jsonInitVal.BuildingType = this.HouseInfo.BuildingType;
            jsonInitVal.HouseUse = this.HouseInfo.HouseUse;
            jsonInitVal.BargainCityId = this.UserInfo.CityId;
            jsonInitVal.BargainCompanyId = this.UserInfo.CompanyId;
        } else if (this.ApplyInfo != undefined) {
            jsonInitVal.Block = this.ApplyInfo.Block;
            jsonInitVal.Region = this.ApplyInfo.Region;
            jsonInitVal.BuildingType = this.ApplyInfo.BuildingType;
            jsonInitVal.HouseUse = this.ApplyInfo.HouseUse;
            jsonInitVal.BargainCityId = this.ApplyInfo.BargainCityId;
            jsonInitVal.BargainCompanyId = this.ApplyInfo.BargainCompanyId;
            jsonInitVal.HouseProperty = this.ApplyInfo.HouseProperty;
        }
        return jsonInitVal;
    },
    loadDefVal: function() {
        //房源信息
        if (this.HouseInfo != undefined) {
            var tbHouse = "tbHouse";
            this.HouseInfo.NewHouseAddress = this.HouseInfo.DetailAddress;
            this.HouseInfo.Area = this.HouseInfo.BuildingArea;
            this.HouseInfo.CurrentFloor = this.HouseInfo.Cur_Floor;
            this.HouseInfo.TotalFloor = this.HouseInfo.Total_Floor;

            //绑定页面房源部分
            Chenxin.Fn.setFormValue(tbHouse, {}, this.HouseInfo);
            //上家门店
            $("#txtVenderDepartName").val(this.HouseInfo.OprDepart);
            //上家业务员
            $("#txtVenderUserName").val(this.HouseInfo.OprPerson);
            //下家门店
            $("#txtBuyerDepartId").val(this.UserInfo.DepartName);
            //下家业务员
            $("#txtBuyerUserId").val(this.UserInfo.UserName);
        }
        //业绩申请信息
        if (this.ApplyInfo != undefined) {
            this.ApplyInfo.OldHouseAddress = this.ApplyInfo.HouseAddress;
            this.ApplyInfo.NewHouseAddress = this.ApplyInfo.HouseAddress;
            //绑定申请业绩部分
            Chenxin.Fn.setFormValue(this.id, this.setComboList, this.ApplyInfo);
            //点数分配备注
            $("#txtaPointRemark").val(this.ApplyInfo.PointRemark);
        }
        //无点数分配信息
        if (this.PointInfo == undefined) {
            this.createTr(false);
        } else {
            if (this.PointInfo.length > 0) {
                for (var idxCnt = 0; idxCnt < this.PointInfo.length; idxCnt++) {
                    this.createTr(false, this.PointInfo[idxCnt]);
                }
            } else {
                this.createTr(false);
            }
        }
    }
});

$(document).ready(function(){
    var objPage = new Chenxin.UI.MainBusinessApplyPage();
});